<div class="row">
	<div class="col-md-12">
		<form id="edit-form" class="form-horizontal" action="${request.contextPath}/system/config/server/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${sysServer.id}">
			<div class="box-body">
				<div class="form-group">
					<label id="serverNameLabel" for="serverName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-4">
						<input class="form-control" name="name" id="serverName" value="${sysServer.name}" type="text" placeholder="输入名称...">
					</div>
					<label id="serverCodeLabel" for="serverCode" class="col-sm-2 control-label" >编码</label>
					<div class="col-sm-4">
						<input  class="form-control" name="code" id="serverCode" value="${sysServer.code}" type="text" placeholder="输入编码...">
					</div>
				</div>
				<div class="form-group">
					<label id="sysServerTypeLabel" for="sysServerType" class="col-sm-2  control-label">类型</label>
					<div class="col-sm-4">
						<select class="form-control" id="sysServerType"  name="type"  style="width: 100%;">
						</select>
					</div>
					<label id="serverUploadDirectoryLabel" for="serverUploadDirectory" class="col-sm-2 control-label">文件上传目录</label>
					<div class="col-sm-4">
						<input class="form-control" name="uploadDirectory" id="serverUploadDirectory" value="${sysServer.uploadDirectory}"  type="text" placeholder="输入文件上传目录...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverHostLabel" for="serverHost" class="col-sm-2 control-label">主机</label>
					<div class="col-sm-4">
						<input  class="form-control" name="host" id="serverHost" value="${sysServer.host}" type="text" placeholder="输入主机...">
					</div>
					<label id="serverPortLabel" for="serverPort" class="col-sm-2 control-label" >端口号</label>
					<div class="col-sm-4">
						<input class="form-control" name="port" id="serverPort" value="${sysServer.port}" type="number"  placeholder="输入端口号...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverUsernameLabel" for="serverUsername" class="col-sm-2 control-label">用户名</label>
					<div class="col-sm-4">
						<input  class="form-control" name="username" id="serverUsername"  value="${sysServer.username}" type="text" placeholder="输入用户名...">
					</div>
					<label id="serverPasswordLabel" for="serverPassword" class="col-sm-2 control-label" >密码</label>
					<div class="col-sm-4">
						<input  class="form-control" name="password" id="serverPassword"  value="${sysServer.password}" type="text" placeholder="输入密码...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverUrlLabel" class="col-sm-2 control-label" >访问URL</label>
					<div class="col-sm-10">
						<input  class="form-control" name="url" id="serverUrl" value="${sysServer.url}" type="text" placeholder="输入访问URL...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverSortOrderLabel" for="serverSortOrder" class="col-sm-2  control-label">排序号</label>
					<div class="col-sm-4">
						<input class="form-control" name="sortOrder" id="serverSortOrder" value="${sysServer.sortOrder}" type="number" placeholder="输入排序号...">
					</div>
					<label id="sysServerStatusLabel" for="sysServerStatus" class="col-sm-2  control-label">状态</label>
					<div class="col-sm-4">
						<select class="form-control" id="sysServerStatus"  name="status" style="width: 100%;" placeholder="选择状态...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="serverDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-10">
						<input  class="form-control" name="description" id="serverDescription" value="${sysServer.description}" type="text" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="serverRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-10">
						<input class="form-control" name="remark" id="serverRemark" value="${sysServer.remark}" type="text" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" >
					<span class="error-icon"></span>
					<span id="error-msg" class="error-msg" ></span>
				</div>
             </div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	var $form = $(form);
	if ($form.length === 1 && $form.validate()) {
        $.ajax({
            type: 'post',
            url: form.action,
            dataType: "json",
            data: $form.serialize()
        }).done(function(result){
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
                dataGridReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        });
	}
}

$(function() {
    $("#sysServerType").select2({
        data: ServerTypeStore,
        placeholder: "选择服务器类型...",
        language: "zh-CN",
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${sysServer.type}').trigger("change");
    $("#sysServerStatus").select2({
        data: StatusStore,
        placeholder: "选择状态...",
        language: "zh-CN",
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${sysServer.status}').trigger("change");

	var $editForm = $("#edit-form");
	$editForm.validate({
		rules: {
            name: {
                required: true
            },
            code: {
                required: true
            },
            type: {
                required: true
            },
            sortOrder: {
                required: true
            }
		},
		messages: {
            name:{
                required:"名称不能为空！"
            },
            code:{
                required:"编码不能为空！"
            },
            type:{
                required:"类型不能为空！"
            },
            sortOrder: {
                required: "排序号不能为空！"
            }
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$editForm.find(".error-msg").html(errorList[0].message);
			}else{
				$editForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>